package jgl.vajra.operator.part.login.activity;

import java.util.HashMap;
import java.util.Map;

import jgl.vajra.operator.R;
import jgl.vajra.operator.bean.LoginInfoBean;
import jgl.vajra.operator.databinding.ActivityUnboundMachineBossBinding;
import jgl.vajra.operator.manager.AccountManager;
import jgl.vajra.operator.part.login.contract.UnboundMachineBossContract;
import jgl.vajra.operator.part.login.viewModel.UnboundMachineBossViewModel;
import jgl.vajra.operator.widget.mvvm.factory.CreateViewModel;
import jgl.vajra.operator.widget.mvvm.view.BaseMVVMActivity;
import jgl.vajra.operator.widget.retrofithelper.utils.AEACCoder;
import jgl.vajra.operator.widget.utils.PhoneUtils;
import jgl.vajra.operator.widget.utils.ToastUtils;
import jgl.vajra.operator.widget.utils.UIUtils;

@CreateViewModel(UnboundMachineBossViewModel.class)
public class UnboundMachineBossActivity extends BaseMVVMActivity<UnboundMachineBossViewModel, ActivityUnboundMachineBossBinding> implements UnboundMachineBossContract.View {
    @Override
    public int getLayoutId() {
        return R.layout.activity_unbound_machine_boss;
    }

    @Override
    public void initView() {
        super.initView();
        mBinding.setView(this);

        mBinding.tvPhone.setText("已绑定的机车老板手机号："+ PhoneUtils.hidePhoneNum(AEACCoder.decrypt(AccountManager.getInstance().getLoginData(UIUtils.getContext()).ownerPhone)));
    }

    //解绑
    @Override
    public void onDetermine() {
        Map<String, Object> map = new HashMap<>();
        map.put("Authorization", AccountManager.getInstance().getLoginData(UIUtils.getContext()).authorization);
        mViewModel.bindMachineData(map);
    }

    @Override
    public void returnBindMachineData() {
        ToastUtils.showShort("解绑成功");
        LoginInfoBean loginData = AccountManager.getInstance().getLoginData(UIUtils.getContext());
        loginData.ownerPhone="";
        AccountManager.getInstance().saveLoginData(this, loginData);
        finish();
    }
}
